/*
 * This file is part of the <a href="http://code.google.com/p/pux">PUX Framework</a>
 *
 * Copyright 2008 by <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package de.teamskill.pux.samples.script;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.jdom.JDOMException;

import de.teamskill.pux.engine.Network;
import de.teamskill.pux.script.NetworkBuilder;

/**
 * ScriptTest1
 *
 * @author <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 *
 */
public class ScriptTest1 {

	/**
	 * main
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		InputStream script;
		try {
			Map<String, String> parameters = new HashMap<String, String>();
			if (args.length > 0) {
				script = new FileInputStream(args[0]);
				for (int i = 1; i < args.length; i += 2) {
					parameters.put(args[i], args[i + 1]);
				}
			} else {
				script = ScriptTest1.class.getResourceAsStream("sample-pux-script-2.xml");
			}
			NetworkBuilder nb = new NetworkBuilder(script, parameters);
			Network n = nb.createNetwork();
			n.start();
		} catch (JDOMException e) {
			System.err.println("Error in PUX Script: " + e.getLocalizedMessage());
			System.exit(1);
		} catch (IOException e) {
			System.err.println("Error reading PUX Script: " + e.getLocalizedMessage());
			System.exit(2);
		}
	}

}
